import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

// 方法一： 手动引入子模块路由
// import newsRouterConfig from './news'
// import productRouterConfig from './product'
// const routers = [...newsRouterConfig, ...productRouterConfig]

// 方法二：自动扫描引入子模块
let routes = [];
const routeContext = require.context('./', true, /index\.js$/);
routeContext.keys().forEach(route => {
  // 当前根目录下的则return掉
  if (route.startsWith('./index')) return;
  const routerMoudule = routeContext(route);
  routes = [...routes, ...(routerMoudule.default || routerMoudule)]
})



export default new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: routes
})